home *** CD-ROM | disk | FTP | other *** search
- Program SaveScrap;
- {
- This module produces a HyperCard XCMD resource to save the
- current contents of the Clipboard as a resource with the
- given type and ID in the current stack. If a resource
- already exists with the same type and ID, it is deleted.
- Call the XCMD from HyperCard as follows:
-
- saveScrap resType, resID
-
- Written by Lawrence D'Oliveiro 1988 January 13.
- Last modified 1988 July 14.
- }
- {$C 'XCMD' 128 'SaveScrap' 32}
- {$H 'XCmdHeader'}
- {$T 'XCMD'}
-
- Uses
- MacIntf,
- HyperXCmd;
-
- Procedure TheProc
- (
- ParamPtr : XCmdPtr
- );
- { actual code for the XCMD. }
-
- Var
- TheResType : ResType;
- TheResID : Integer;
- TheScrap : PScrapStuff;
- WasOnDisk : Boolean;
- TheResource : Handle;
- Err : OSErr;
-
- Procedure GetResTypeAndID;
- { get resource type and ID. }
-
- Var
- ResIDString : Str255;
-
- Begin
- BlockMove(ParamPtr^.Params[1]^, @TheResType, 4);
- ZeroToPas(ParamPtr, ParamPtr^.Params[2]^, ResIDString);
- TheResID := StrToNum(ParamPtr, ResIDString)
- End {GetResTypeAndID};
-
- Procedure ReturnError
- (
- Error : Integer
- );
- { return error number as a string. }
-
- Var
- ErrorString : Str255;
-
- Begin
- NumToString(Error, ErrorString);
- ParamPtr^.ReturnValue := PasToZero(ParamPtr, ErrorString)
- End {ReturnError};
-
- Begin {TheProc}
- GetResTypeAndID;
- { ensure no duplicate resources }
- TheResource := Get1Resource(TheResType, TheResID);
- If TheResource <> Nil then
- RmveResource(TheResource);
- TheScrap := InfoScrap;
- Err := NoErr;
- WasOnDisk := TheScrap^.ScrapState = 0;
- If WasOnDisk then
- Err := LoadScrap;
- If Err = NoErr then
- Begin
- TheResource := TheScrap^.ScrapHandle;
- Err := HandToHand(TheResource);
- If Err = NoErr then
- Begin
- AddResource(TheResource, TheResType, TheResID, '');
- Err := ResError;
- If Err = NoErr then
- Begin
- SetResAttrs(TheResource, BitOr(GetResAttrs(TheResource), ResPurgeable));
- UpdateResFile(CurResFile);
- Err := ResError;
- HPurge(TheResource)
- End
- else
- DisposHandle(TheResource)
- End {If}
- End {If};
- If Err <> NoErr then
- ReturnError(Err);
- If WasOnDisk then
- Err := UnloadScrap
- End {TheProc};
-
- Begin {SaveScrap}
- { dummy mainline }
- End {SaveScrap}.
-